package com.hupu.jrs.util

import android.app.Activity
import android.content.Context
import android.support.annotation.AttrRes
import com.github.clans.fab.FloatingActionButton
import com.github.clans.fab.FloatingActionMenu
import com.hupu.jrs.R

/**
 * Created by sll on 2015/9/6 0006.
 */
object ResourceUtil {

    fun getThemeColor(context: Context): Int {
        return getThemeAttrColor(context, R.attr.colorPrimary)
    }

    fun getThemeAttrColor(context: Context, @AttrRes attr: Int): Int {
        val a = context.obtainStyledAttributes(null, intArrayOf(attr))
        try {
            return a.getColor(0, 0)
        } finally {
            a.recycle()
        }
    }

    fun getStatusBarHeight(mContext: Context): Int {
        var result = 0
        val resourceId = mContext.resources.getIdentifier("status_bar_height", "dimen", "android")
        if (resourceId > 0) {
            result = mContext.resources.getDimensionPixelSize(resourceId)
        }
        return result
    }

    fun setFabBtnColor(activity: Activity, fab: FloatingActionButton) {
        // 更新FAB的颜色
        fab.colorNormal = getThemeColor(activity)
        fab.colorPressed = getThemeColor(activity)
        fab.colorRipple = getThemeColor(activity)
    }

    fun setFabMenuColor(activity: Activity, fab: FloatingActionMenu) {
        // 更新FAB的颜色
        fab.menuButtonColorNormal = getThemeColor(activity)
        fab.menuButtonColorPressed = getThemeColor(activity)
        fab.menuButtonColorRipple = getThemeColor(activity)
    }
}
